<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_region.tpl'}-->
    <title>收货地址精度</title>
</head>
<body>

<style>
    .col-sm-2{
        width:100px;
    }
</style>

<div class="container">

 
        <div class="comm_content">

            <div id="pop" >

                <form id="item_form" onsubmit="return false;" class="form-horizontal">


                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="address_detail">
                            <span class="red">*</span>
                            地址：
                        </label>
                        <div class="col-sm-10">
                            <p class="form-control-static fl" id="address_detail"><!--{$address}--></p>
                            <input type="hidden" name="deliverID" id="deliver_id" value="<!--{$deliverID}-->">
                        </div>
                    </div>


                    <div class="form-group map" >
                        <label class="col-sm-2 control-label" for="longitude">
                            <span class="red">*</span>
                            经度：
                        </label>
                        <div class="col-sm-10">
                            <input id="longitude" class="form-control w300" type="text" name="longitude" readonly="readonly" value="<!--{$longitude}-->">
                        </div>
                    </div>

                    <div class="form-group map">
                        <label class="col-sm-2 control-label" for="latitude">
                            <span class="red">*</span>
                            纬度：
                        </label>
                        <div class="col-sm-10">
                            <input id="latitude" class="form-control w300" type="text" name="latitude" readonly="readonly" value="<!--{$latitude}-->">
                        </div>
                    </div>

                    <div class="form-group map" id="map_tr">
                        <label class="col-sm-2 control-label" for="latitude">

                        </label>
                        <div class="tar"></div>
                        <div class="col-sm-10" style="height:500px; padding-bottom:5px;">
                            <div id="allmap" style="height:500px; width:960px;"></div>
                        </div>

                    </div>

                </form>
            </div>



        </div>




    <div class="bottom_fixbox">
        <div class="tac" style="background: #dddddd;">
            <input type="button" class="btn btn-primary" onclick="address_precision.check();" value="保存" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn btn-default" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>
</div>



<script type="text/javascript" src="/inc/config/default/region.min.js"></script>
<script type="text/javascript" src="/framework/ebsig/js/region.change.min.js"></script>
<!--baidu map-->
<!--{include file="comm/baidu_map.tpl"}-->

<script type="text/javascript">

    $(document).ready(function(){
        showMap( '<!--{$address}-->' );
    });
    var address_precision = {



        //字段校验
        check: function() {

            this.dt = E.getFormValues('item_form');

            this.dt.provinceName = this.dt.provinceid != "" ? $("#oneLevelID option:selected").text() : '';
            this.dt.cityName = this.dt.cityid != "" ? $("#secondLevelID option:selected").text() : '';
            this.dt.countyName = this.dt.countyid != "" ? $("#threeLevelID option:selected").text() : ''

            var error_msg = '';

            if(E.isEmpty(this.dt.longitude)){
                error_msg +="经度信息不能为空<br>";
            }

            if(E.isEmpty(this.dt.latitude)){
                error_msg +="纬度信息不能为空<br>";
            }

            if (error_msg != '') {

                E.alert(error_msg);

            } else {

                E.confirm("您确认要修改收货地址信息？", function() {

                    //this.dt.address = $("#provinceName").text();

                    E.loadding.open('正在保存，请稍候...');

                    E.ajax_post({
                        url:  '/invokingAjax-backend/send/addressPrecision.ajax?operFlg=100&act=edit',
                        data: address_precision.dt,
                        call: function( o ) {
                            E.loadding.close();
                            if (o.code == 200) {
                                E.opener('address_precision.load');
                                E.alert(o.message, 2, 'E.closeWindows');
                            } else {
                                E.alert(o.message);
                            }
                        }
                    });
                });
            }
        },


        //重新加载
        load: function() {
            $("#flex").flexReload();
        }

    };

    //显示省市区
    E.region.init({
        p: 'oneLevelID',
        c: 'secondLevelID',
        a: 'threeLevelID'

    });

    //百度地图显示
    function showMap ( address ) {

        var map = new BMap.Map("allmap");
        map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));
        map.enableScrollWheelZoom();
        var myGeo = new BMap.Geocoder();

        myGeo.getPoint( address, function(point){
            if(point){
                var lng = $('#longitude').val();
                var lat = $('#latitude').val();
                if((lng != '') && (lat !='') && (parseInt(lng)!=0)&& (parseInt(lat)!=0)){
                    var point = new BMap.Point(lng, lat);
                }else{
                    $('#longitude').val(point.lng);
                    $('#latitude').val(point.lat);
                }
                map.centerAndZoom(point, 14);
                var marker = new BMap.Marker(point);


                //开启坐标点拖拽属性
                marker.enableDragging();

                //在地图上设置坐标点
                map.addOverlay(marker);
                //marker下坠效果
                marker.setAnimation(BMAP_ANIMATION_DROP);

                //设置信息窗口
                var opts = {
                    width : 0,     // 信息窗口宽度
                    height: 0,     // 信息窗口高度
                    enableMessage:false,
                    enableCloseOnClick:false,
                    title : "<span style='color:red;font-weight:bold;'>位置不对吗？？</span>"  // 信息窗口标题
                };
                var html = '<div class="infoWindow_content">快来拖动此图标到达正确位置</div>';
                var infoWindow = new BMap.InfoWindow(html,opts);
                marker.openInfoWindow(infoWindow);

                //开始拖拽
                marker.addEventListener("dragstart", function(e){
                    marker.closeInfoWindow(infoWindow);
                });

                //结束拖拽
                marker.addEventListener("dragend", function(e){
                    myGeo.getLocation(e.point, function(rs){
                        $('#longitude').val(e.point.lng);
                        $('#latitude').val(e.point.lat);
                    });
                });
            }
        });

    }
</script>

</body>

</html>
